package org.example.domain.activity_manage.service.Impl;

import lombok.extern.slf4j.Slf4j;
import org.example.domain.activity_manage.model.entity.PrizeEntity;
import org.example.domain.activity_manage.repository.IPrizeRepo;
import org.example.domain.activity_manage.service.IPrizeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lxc18
 * @date 2025/3/19 15:10
 * @description IPrizeServiceImpl
 */
@Slf4j
@Service
public class IPrizeServiceImpl implements IPrizeService {
    private static final Logger logger = LoggerFactory.getLogger(IPrizeServiceImpl.class);

    @Resource
    private IPrizeRepo prizeRepo;
    @Override
    public boolean createPrize(PrizeEntity prizeEntity) {
        try {
            prizeRepo.createPrize(prizeEntity);
            return true;
        } catch (Exception e) {
            logger.error("创建奖品失败:{}", e.getMessage());
            return false;
        }
    }

    @Override
    public boolean deletePrize(Long prizeId) {
        try {
            prizeRepo.deletePrize(prizeId);
            return true;
        }
        catch (Exception e){
            logger.error("删除奖品失败:{}",e.getMessage());
            return false;
        }
    }

    @Override
    public boolean updatePrize(PrizeEntity prizeEntity) {
        try {
            prizeRepo.updatePrize(prizeEntity);
            return true;
        }
        catch (Exception e){
            logger.error("更新奖品失败:{}",e.getMessage());
            return false;
        }
    }

    @Override
    public List<PrizeEntity> queryPrizeByName(String prizeName) {
        return prizeRepo.queryPrizeByName(prizeName);
    }

    @Override
    public PrizeEntity queryPrizeById(Long prizeId) {
        return prizeRepo.queryPrizeById(prizeId);
    }

    @Override
    public List<PrizeEntity> queryPrizeByPage(int pageNum, int pageSize) {
        return prizeRepo.queryPrizeByPage(pageNum, pageSize);
    }

    @Override
    public boolean updatePrizeStock(Long prizeId, int stock) {
        return prizeRepo.updatePrizeStock(prizeId, stock);
    }

    @Override
    public int queryPrizeStock(Long prizeId) {
        return prizeRepo.queryPrizeStock(prizeId);
    }

    @Override
    public int queryPrizeUsedStock(Long prizeId) {
        return prizeRepo.queryPrizeUsedStock(prizeId);
    }


}
